package com.ablog.controller;

import com.ablog.model.Comment;
import com.ablog.service.CommentService;
import com.ablog.util.ResultUtil;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * (Comment)表控制层
 *
 * @author mopeiwen
 * @since 2020-07-22 13:17:41
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    /**
     * 服务对象
     */
    @Resource
    private CommentService commentService;
    
     /**
     * Select list ResultUtil.
     *
     * @param comment
     * @return the ResultUtil
     */
    @GetMapping(value = "/query-all")
    public ResultUtil queryAll(Comment comment) {
        return ResultUtil.ok("查询列表", commentService.queryAll(comment));
    }
    
    /**
     * 分页查询
     * @param comment
     * @return
     */
    @GetMapping(value = "/query-all-page")
    public ResultUtil queryAllPage(Comment comment,int pagesize,int pagenum) {
        return ResultUtil.ok("查询列表", commentService.queryAll(comment, pagesize, pagenum));
    }
    
    /**
     * Select obj ResultUtil.
     *
     * @param id
     * @return the ResultUtil
     */
    @GetMapping(value = "/query")
    public ResultUtil queryById(@RequestParam("id") String id) {
        return ResultUtil.ok("查询详情", commentService.queryById(id));
    }
    
    /**
     * Insert obj ResultUtil.
     *
     * @param comment
     * @return the ResultUtil
     */
    @PostMapping(value = "/add")
    public ResultUtil add(@Valid @RequestBody Comment comment) {
        return ResultUtil.ok("添加成功", commentService.add(comment));
    }
    
    /**
     * update obj ResultUtil.
     *
     * @param comment
     * @return the ResultUtil
     */
    @PutMapping(value = "/update")
    public ResultUtil update(@Valid @RequestBody Comment comment) {
        return ResultUtil.ok("更新成功", commentService.update(comment));
    }
    
     /**
     * delete obj ResultUtil.
     *
     * @param id
     * @return the ResultUtil
     */
    @DeleteMapping(value = "/del")
    public ResultUtil delById(@RequestParam("id") String id) {
        return ResultUtil.ok("删除成功", commentService.delById(id));
    }
}